package top.ffhome.concurrent.beautiful.ch01;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

public class YieldTest implements Runnable {
    private static final Log log = LogFactory.get();

    YieldTest() {
        Thread t = new Thread(this);
        t.start();
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            if ((i % 5) == 0) {
                log.info("{} yield cpu...", Thread.currentThread());
                Thread.yield();
            }
        }
        log.info("{} is over", Thread.currentThread());
    }

    public static void main(String[] args) throws InterruptedException {
        new YieldTest();
        new YieldTest();
        new YieldTest();
    }
}
